home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / hpljii.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  10.4 KB  |  407 lines

  1. /*
  2.  * $Id: hpljii.trm,v 1.9 1995/12/20 21:47:54 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - hpljii.trm */
  7. /*
  8.  * Copyright (C) 1990 - 1993   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *  hpljii, hpdj
  26.  *
  27.  * AUTHORS
  28.  *  John Engels
  29.  *  Russell Lang
  30.  *  Maurice Castro
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  33.  * 
  34.  */
  35.  
  36. /* The following HP laserjet series II driver uses generic bit mapped graphics
  37.    routines from bitmap.c to build up a bit map in memory.  The driver
  38.    interchanges colomns and lines in order to access entire lines
  39.    easily and returns the lines to get bits in the right order :
  40.    (x,y) -> (y,XMAX-1-x). */
  41. /* This interchange is done by calling b_makebitmap() with reversed 
  42.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  43.    will then perform the interchange before each pixel is plotted */
  44. /* by John Engels JENGELS@BNANDP51.BITNET, inspired by the hpljet driver
  45.    of Jyrki Yli-Nokari */
  46.  
  47. /*
  48.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  49.  */
  50.  
  51. #ifdef GOT_DRIVER_H
  52. #include "driver.h"
  53. #endif
  54.  
  55. #ifdef TERM_REGISTER
  56. register_term(hpljii)
  57. register_term(hpdj)
  58. #endif
  59.  
  60. #ifdef TERM_PROTO
  61. TERM_PUBLIC void HPLJIIoptions __P((void));
  62. TERM_PUBLIC void HPLJIIinit __P((void));
  63. TERM_PUBLIC void HPLJIIgraphics __P((void));
  64. TERM_PUBLIC void HPLJIItext __P((void));
  65. TERM_PUBLIC void HPLJIIlinetype __P((int linetype));
  66. TERM_PUBLIC void HPLJIIput_text __P((unsigned int x, unsigned int y, char *str));
  67. TERM_PUBLIC void HPLJIIreset __P((void));
  68. #define HPLJIImove b_move
  69. #define HPLJIIvector b_vector
  70. #define HPLJIItext_angle b_text_angle
  71. TERM_PUBLIC void HPDJgraphics __P((void));
  72. TERM_PUBLIC void HPDJtext __P((void));
  73. #define HPDJtext_angle b_text_angle
  74. #define HPDJput_text b_put_text
  75. /* default values for term_tbl */
  76. #define HPLJII_75PPI_XMAX (1920/4)
  77. #define HPLJII_75PPI_YMAX (1920/4)
  78. #define HPLJII_75PPI_HCHAR (1920/4/6)
  79. #define HPLJII_75PPI_VCHAR (1920/4/10)
  80. #define HPLJII_75PPI_VTIC 5
  81. #define HPLJII_75PPI_HTIC 5
  82. #endif
  83.  
  84. #ifndef TERM_PROTO_ONLY
  85. #ifdef TERM_BODY
  86.  
  87. /* We define 4 different print qualities : 300ppi, 150ppi, 100ppi and
  88.    75ppi.  (Pixel size = 1, 2, 3, 4 dots) */
  89.  
  90. #define HPLJII_DPP (hplj_dpp)   /* dots per pixel */
  91. #define HPLJII_PPI (300/HPLJII_DPP) /* pixel per inch */
  92. /* make XMAX and YMAX a multiple of 8 */
  93. #define HPLJII_XMAX (8*(unsigned int)(xsize*1920/HPLJII_DPP/8.0+0.9))
  94. #define HPLJII_YMAX (8*(unsigned int)(ysize*1920/HPLJII_DPP/8.0+0.9))
  95.  
  96. #define HPLJII_VCHAR (HPLJII_PPI/6) /* Courier font with 6 lines per inch */
  97. #define HPLJII_HCHAR (HPLJII_PPI/10) /* Courier font with 10 caracters
  98.                                         per inch */
  99.  
  100. #define HPLJII_PUSH_CURSOR fprintf(outfile,"\033&f0S") /* Save current
  101.                   cursor position */
  102. #define HPLJII_POP_CURSOR fprintf(outfile,"\033&f1S") /* Restore
  103.                   cursor position */
  104. #define HPLJII_COURIER fprintf(outfile,"\033(0N\033(s0p10.0h12.0v0s0b3T\033&l6D")
  105.          /* be sure to use courier font with 6lpi and 10cpi */
  106.  
  107. void HPLJIIputc __P((unsigned int x, unsigned int y, char c, int angle));
  108. static int hplj_dpp=4;
  109. /* bm_pattern not appropriate for 300ppi graphics */
  110. #ifndef GOT_300_PATTERN
  111. #define GOT_300_PATTERN
  112. static unsigned int b_300ppi_pattern[] = {0xffff, 0x1111,
  113.         0xffff, 0x3333, 0x0f0f, 0x3f3f, 0x0fff, 0x00ff, 0x33ff};
  114. #endif
  115.  
  116. TERM_PUBLIC void HPLJIIoptions()
  117. {
  118. char opt[4];
  119. int parse_error=0;
  120.  
  121.     if (END_OF_COMMAND) {
  122.         term_options[0]='\0';
  123.     } else {
  124.         if (token[c_token].length>3) {
  125.             parse_error=1; /* see below */
  126.         } else {
  127.         /* almost_equals() won't accept numbers - use strcmp() instead */
  128.         capture(opt,c_token,c_token, 4);
  129.         if (!strcmp(opt,"75")) {
  130.                hplj_dpp = 4;
  131.         }
  132.         else if (!strcmp(opt,"100")) {
  133.                hplj_dpp = 3;
  134.         }
  135.         else if (!strcmp(opt,"150")) {
  136.                hplj_dpp = 2;
  137.         }
  138.         else if (!strcmp(opt,"300")) {
  139.                hplj_dpp = 1;
  140.         } else {
  141.         /* error, but set dpi anyway, since term it already set */
  142.                 parse_error=1;
  143.         }
  144.         c_token++;
  145.     }
  146.     }
  147.  
  148.     term->xmax = HPLJII_XMAX;
  149.     term->ymax = HPLJII_YMAX;
  150.     switch(hplj_dpp) {
  151.         case 1:
  152.             strcpy(term_options,"300");
  153.             term->v_tic = 15;
  154.             term->h_tic = 15;
  155.             break;
  156.         case 2:
  157.             strcpy(term_options,"150");
  158.             term->v_tic = 8;
  159.             term->h_tic = 8;
  160.             break;
  161.         case 3:
  162.             strcpy(term_options,"100");
  163.             term->v_tic = 6;
  164.             term->h_tic = 6;
  165.             break;
  166.         case 4:
  167.             strcpy(term_options,"75");
  168.             term->v_tic = 5;
  169.             term->h_tic = 5;
  170.             break;
  171.     }
  172.  
  173.     if( parse_error ) 
  174.         int_error("expecting dots per inch size 75, 100, 150 or 300",
  175.                 c_token);
  176. }
  177.  
  178.  
  179. TERM_PUBLIC void HPLJIIinit()
  180. {
  181. #ifdef REOPEN_BINARY
  182.    reopen_binary();
  183. #endif /* REOPEN_BINARY */
  184. }
  185.  
  186.  
  187. TERM_PUBLIC void HPLJIIgraphics()
  188. {
  189.    term->v_char = HPLJII_VCHAR;
  190.    term->h_char = HPLJII_HCHAR;
  191.    HPLJII_COURIER;
  192.    HPLJII_PUSH_CURSOR;
  193.    /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  194.       setting b_rastermode to TRUE */
  195.    b_makebitmap(HPLJII_YMAX,HPLJII_XMAX,1);
  196.    b_rastermode = TRUE;
  197. }
  198.  
  199.  
  200. /* HPLJIItext by rjl - no compression */
  201. TERM_PUBLIC void HPLJIItext()
  202. {
  203.   register int x,j,row;
  204.  
  205.    fprintf(outfile,"\033*t%dR", HPLJII_PPI);
  206.    HPLJII_POP_CURSOR;
  207.    fprintf(outfile, "\033*r1A");
  208.  
  209.    /* dump bitmap in raster mode */
  210.    for (x = b_xsize-1; x >= 0; x--) {
  211.       row = (b_ysize/8)-1;
  212.       fprintf(outfile, "\033*b0m%dW", b_ysize/8);
  213.       for (j = row; j >= 0; j--) {
  214.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  215.       }
  216.    }
  217.    fprintf(outfile, "\033*rB");
  218.  
  219.    b_freebitmap();
  220.  
  221. #ifndef vms  /* most vms spoolers add a formfeed character */
  222.    fprintf(outfile,"\f");
  223. #endif /* not vms */
  224. }
  225.  
  226.  
  227.  
  228. TERM_PUBLIC void HPLJIIlinetype(linetype)
  229. int linetype;
  230. {
  231.  
  232.    if (hplj_dpp == 1) {
  233.       if (linetype>=7)
  234.           linetype %= 7;
  235.       /* b_pattern not appropriate for 300ppi graphics */
  236.       b_linemask = b_300ppi_pattern[linetype+2];
  237.       b_maskcount=0;
  238.    }
  239.    else {
  240.       b_setlinetype(linetype);
  241.    }
  242. }
  243.  
  244. TERM_PUBLIC void HPLJIIput_text(x,y,str)
  245. unsigned int x, y;
  246. char *str;
  247. {
  248.    switch (b_angle) {
  249.       case 0:
  250.          y -= HPLJII_VCHAR/5;
  251.          HPLJII_POP_CURSOR;
  252.          HPLJII_PUSH_CURSOR;
  253.          /* (0,0) is the upper left point of the paper */
  254.          fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  255.                                          ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  256.          fputs(str, outfile);
  257. /*       for (; *str; ++str, x += HPLJII_HCHAR)
  258.             HPLJIIputc (x, y, *str, b_angle);*/
  259.          break;
  260.       case 1:
  261.          y += (HPLJII_HCHAR-2*HPLJII_VCHAR)/2;
  262.          y += (HPLJII_VCHAR+HPLJII_HCHAR)*strlen(str)/2;
  263.          for (; *str; ++str, y -= HPLJII_VCHAR)
  264.             HPLJIIputc (x, y, *str, b_angle);
  265.          break;
  266.    }
  267. }
  268.  
  269. #ifdef ANSI_C
  270. void HPLJIIputc(unsigned int x, unsigned int y, char c, int angle)
  271. #else
  272. void HPLJIIputc(x,y,c,angle)
  273. unsigned int x,y;
  274. int angle;
  275. char c;
  276. #endif
  277. {
  278.    HPLJII_POP_CURSOR;
  279.    HPLJII_PUSH_CURSOR;
  280.    /* (0,0) is the upper left point of the paper */
  281.    fprintf(outfile, "\033*p%+dx%+dY", x*HPLJII_DPP
  282.                                    ,  (HPLJII_YMAX-y-1)*HPLJII_DPP );
  283.    fputc(c, outfile);
  284. }
  285.  
  286.  
  287. TERM_PUBLIC void HPLJIIreset()
  288. {
  289. #ifdef vms
  290.    fflush_binary();
  291. #endif /* vms */
  292. }
  293.  
  294.  
  295. /* HP DeskJet routines */
  296. TERM_PUBLIC void HPDJgraphics()
  297. {
  298.     switch(hplj_dpp) {
  299.         case 1:
  300.             b_charsize(FNT13X25);
  301.             term->v_char = FNT13X25_VCHAR;
  302.             term->h_char = FNT13X25_HCHAR;
  303.             break;
  304.         case 2:
  305.             b_charsize(FNT13X25);
  306.             term->v_char = FNT13X25_VCHAR;
  307.             term->h_char = FNT13X25_HCHAR;
  308.             break;
  309.         case 3:
  310.             b_charsize(FNT9X17);
  311.             term->v_char = FNT9X17_VCHAR;
  312.             term->h_char = FNT9X17_HCHAR;
  313.             break;
  314.         case 4:
  315.             b_charsize(FNT5X9);
  316.             term->v_char = FNT5X9_VCHAR;
  317.             term->h_char = FNT5X9_HCHAR;
  318.             break;
  319.     }
  320.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  321.     setting b_rastermode to TRUE */
  322.     b_makebitmap(HPLJII_YMAX,HPLJII_XMAX,1);
  323.     b_rastermode = TRUE;
  324. }
  325.  
  326.  
  327. /* 0 compression raster bitmap dump. Compatible with HP DeskJet 500
  328.    hopefully compatible with other HP Deskjet printers */
  329. TERM_PUBLIC void HPDJtext()
  330. {
  331.   register int x,j,row;
  332.  
  333.    fprintf(outfile,"\033*b0M");
  334.    fprintf(outfile,"\033*t%dR", HPLJII_PPI);
  335.    fprintf(outfile, "\033*r1A");
  336.  
  337.    /* dump bitmap in raster mode */
  338.    for (x = b_xsize-1; x >= 0; x--) {
  339.       row = (b_ysize/8)-1;
  340.       fprintf(outfile, "\033*b%dW", b_ysize/8);
  341.       for (j = row; j >= 0; j--) {
  342.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  343.       }
  344.    }
  345.    fprintf(outfile, "\033*rbC");
  346.  
  347.    b_freebitmap();
  348.  
  349. #ifndef vms  /* most vms spoolers add a formfeed character */
  350.    fprintf(outfile,"\f");
  351. #endif /* not vms */
  352. }
  353.  
  354. #endif 
  355.  
  356. #ifdef TERM_TABLE
  357.  
  358. TERM_TABLE_START(hpljii_driver)
  359.     "hpljii", "HP Laserjet series II, [75 100 150 300]",
  360.        HPLJII_75PPI_XMAX, HPLJII_75PPI_YMAX, HPLJII_75PPI_VCHAR,
  361.        HPLJII_75PPI_HCHAR, HPLJII_75PPI_VTIC, HPLJII_75PPI_HTIC, HPLJIIoptions,
  362.        HPLJIIinit, HPLJIIreset, HPLJIItext, null_scale,
  363.        HPLJIIgraphics, HPLJIImove, HPLJIIvector, HPLJIIlinetype,
  364.        HPLJIIput_text, HPLJIItext_angle, null_justify_text, line_and_point,
  365.        do_arrow, set_font_null
  366. TERM_TABLE_END(hpljii_driver)
  367. #undef LAST_TERM
  368. #define LAST_TERM hpljii_driver
  369.  
  370. TERM_TABLE_START(hpdj_driver)
  371.     "hpdj", "HP DeskJet 500, [75 100 150 300]",
  372.        HPLJII_75PPI_XMAX, HPLJII_75PPI_YMAX, HPLJII_75PPI_VCHAR,
  373.        HPLJII_75PPI_HCHAR, HPLJII_75PPI_VTIC, HPLJII_75PPI_HTIC, HPLJIIoptions,
  374.        HPLJIIinit, HPLJIIreset, HPDJtext, null_scale,
  375.        HPDJgraphics, HPLJIImove, HPLJIIvector, HPLJIIlinetype,
  376.        HPDJput_text, HPDJtext_angle, null_justify_text, line_and_point,
  377.        do_arrow, set_font_null
  378. TERM_TABLE_END(hpdj_driver)
  379.  
  380. #undef LAST_TERM
  381. #define LAST_TERM hpdj_driver
  382.  
  383. #endif
  384. #endif
  385.  
  386. /*
  387.  * NAME: hpljii
  388.  *
  389.  * OPTIONS: dpi (legal 75, 100, 150, 300; default = 75)
  390.  *
  391.  * SUPPORTS: HP Laserjet Series II
  392.  *
  393.  * Further Info: none
  394.  *
  395.  */
  396.  
  397. /*
  398.  * NAME: hpdj
  399.  *
  400.  * OPTIONS: dpi (legal 75, 100, 150, 300; default = 75)
  401.  *
  402.  * SUPPORTS: HP DeskJet 500 ink printer
  403.  *
  404.  * Further Info: There is another terminal (hp500c) that supports
  405.  *         colours and compression.
  406.  *
  407.  */